package xyz.ddlnt.commonutil.util;

import cn.dev33.satoken.stp.StpUtil;
import jakarta.servlet.http.HttpServletRequest;
import xyz.ddlnt.commonutil.constant.HttpConstants;

/**
 * @author ZZULI_SE 210910
 * @data 2025/5/8 22:09
 */
public class HttpUtils {

    /**
     * 通过请求头从SaToken中获取用户id
     * @param request
     * @return
     */
    public static Long getId(HttpServletRequest request) {
        String satoken = request.getHeader(HttpConstants.SATOKEN);
        String userId = StpUtil.getLoginIdByToken(satoken).toString();
        return Long.parseLong(userId);
    }
}
